<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-menu.tld" prefix="menu" %>
<%@ taglib uri="/WEB-INF/tlds/struts-menu-el.tld" prefix="menu-el" %>
<%@ taglib uri="/WEB-INF/tlds/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tlds/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tlds/authz.tld" prefix="authz" %>
<%@ taglib uri="/WEB-INF/tlds/sitemesh-decorator.tld" prefix="decorator" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" scope="request"/>
<script type="text/javascript">
<!--	
	function addAttr() {
		var id = $F("currentIntId");
		popup('${ctx}/filter.do?method=edit&decorator=popup&confirm=true&intId='+id, 'popupFil', 400, 280);
	}
	function modifyAttr() {
		var attrVal=checkValue($('filForm'),'id');
		var id = $F("currentIntId");
		if(!attrVal || attrVal.length==0) {
			alert('<bean:message key="info.selectAttributeFilter" />');
		} else {
			popup('${ctx}/filter.do?method=edit&decorator=popup&confirm=true&id='+attrVal+'&intId='+id, 'popupFil', 400, 280);
		}
	}
	function deleteAttr() {
		var attrVal=checkValue($('filForm'),'id');
		if(!attrVal || attrVal.length==0) {
			alert('<bean:message key="info.selectAttributeFilter" />');
		} else if(confirm('<bean:message key="info.confirmDeletion" />')) {
			$('methodFil').value='delete';
			$('filForm').submit();
		}
	}
			
	function addFil() {
		var intVal=checkValue($('filForm'),'intId');
		if(!intVal || intVal.length==0) {
			alert('<bean:message key="info.selectInterFilter" />');
		} else {
			$('methodFil').value='intSave';
			$('filForm').submit();
		}
	}
	function deleteFil() {
		var intVal=checkValue($('filForm'),'intId');
		if(!intVal || intVal.length==0) {
			alert('<bean:message key="info.selectInterFilter" />');
		} else if(confirm('<bean:message key="info.confirmDeletion" />')) {
			$('methodFil').value='intDelete';
			$('filForm').submit();
		}
	}
			
	function validateFilter() {
		var value = $F("globalValue");
		this.opener.document.resourceForm.filter.value=value;
		closePopup();
	}
	
	function selectIntFilter(){
		var interFilter=checkValue($('filForm'),'intId');
		document.forms[0].action='${ctx}/filter.do?method=selectFilter&amp;decorator=popup&amp;confirm=true&interFilter='+interFilter;
		document.forms[0].submit();
	}
	
	function selectOp(){
		var currentOp=checkValue($('filForm'),'operator');
		document.forms[0].action='${ctx}/filter.do?method=selectOp&amp;decorator=popup&amp;confirm=true&amp;operator='+currentOp;
		document.forms[0].submit();
	}
	
	function selectGlobOp(){
		var currentOp=checkValue($('filForm'),'globOperator');
		document.forms[0].action='${ctx}/filter.do?method=selectGlobOp&amp;decorator=popup&amp;confirm=true&amp;globOperator='+currentOp;
		document.forms[0].submit();
	}
//  -->
</script>
<div id="subcontent">
	<html:form styleId="filForm" action="/filter">
		<input type="hidden" id="decorator" name="decorator" value="popup" />
		<input type="hidden" id="confirm" name="confirm" value="true" />
		<input type="hidden" id="methodFil" name="method" value="" />
		<html:hidden property="intFilter.id" styleId="currentIntId"/>
		<p><bean:message key="filterPage.filterDefinition" /></p>
		<p>
			<table class="list" id="filterList">
				<thead>
					<tr>
						<th>-</th>
						<th><bean:message key="filterPage.operation" /></th>
						<th><bean:message key="filterPage.not" /></th>
						<th><bean:message key="filterPage.attribute" /></th>
						<th><bean:message key="filterPage.value" /></th>
					</tr>
				</thead>
				<tbody>
					<c:forEach var="filter" items="${filters}" end="0">
						<tr>
							<td><input type="radio" name="id" value="${filter.id}" /></td>
							<td></td>
							<td><c:choose>
									<c:when test='${filter.non}'>
										<input type="checkbox" id="non" checked disabled="true" />
									</c:when>
									<c:otherwise>
										<input type="checkbox" id="non" disabled="true" />
									</c:otherwise>
							</c:choose></td>
							<td><c:out value="${filter.attribute}" /></td>
							<td><c:choose>
									<c:when test='${filter.ident}'>
										\${<c:out value="${filter.value}" />}
									</c:when>
									<c:otherwise>
											<c:out value="${filter.value}" />
									</c:otherwise>
							</c:choose></td>
						</tr>
					</c:forEach>
					<c:forEach var="filter" items="${filters}" begin="1">
						<tr>
							<td><input type="radio" name="id" value="${filter.id}" /></td>
							<td><c:out value="${intFilter.operator}" /></td>
							<td><c:choose>
									<c:when test='${filter.non}'>
										<input type="checkbox" id="non" checked disabled="true" />
									</c:when>
									<c:otherwise>
										<input type="checkbox" id="non" disabled="true" />
									</c:otherwise>
							</c:choose></td>
							<td><c:out value="${filter.attribute}" /></td>
							<td><c:choose>
									<c:when test='${filter.ident}'>
										\${<c:out value="${filter.value}" />}
									</c:when>
									<c:otherwise>
											<c:out value="${filter.value}" />
									</c:otherwise>
							</c:choose></td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</p>
		<p><c:choose>
				<c:when test='${intFilter.operator=="OU"}'>
					<bean:message key="filterPage.and" />
					<input type="radio" name="operator" value="ET" onClick="selectOp();"/>&nbsp;
					<bean:message key="filterPage.or" />
					<input type="radio"	name="operator" value="OU" checked onClick="selectOp();"/>
				</c:when>
				<c:when test='${intFilter.operator=="ET"}'>
					<bean:message key="filterPage.and" />
					<input type="radio" name="operator" value="ET" checked onClick="selectOp();"/>&nbsp;
					<bean:message key="filterPage.or" />
					<input type="radio"	name="operator" value="OU" onClick="selectOp();"/>
				</c:when>
				<c:otherwise>
					<bean:message key="filterPage.and" />
					<input type="radio" name="operator" value="ET" onClick="selectOp();" />&nbsp;
					<bean:message key="filterPage.or" />
					<input type="radio"	name="operator" value="OU" onClick="selectOp();" />
				</c:otherwise>
		</c:choose> </p>
		<p>	<input name="addAttrButton" type="submit" value="<bean:message key="filterPage.add" />" onclick="addAttr();return false;" />&nbsp;
			<input name="modifyAttrButton" type="submit" value="<bean:message key="filterPage.modify" />" onclick="modifyAttr();return false;" />&nbsp;
			<input name="delAttrButton" type="submit" value="<bean:message key="filterPage.delete" />"	onclick="deleteAttr();return false;" />
		</p>
		<p>
			<table class="list" id="intFilterList">
				<thead>
					<tr>
						<th>-</th>
						<th><bean:message key="filterPage.operation" /></th>
						<th><bean:message key="filterPage.intFilter" /></th>
					</tr>
				</thead>
				<tbody>
				<c:forEach var="filtInt" items="${intFilters}" end="0">
						<tr>
							<td><c:choose>
								<c:when test='${filtInt.id==intFilter.id}'>
									<input type="radio" name="intId" value="${filtInt.id}" onClick="selectIntFilter();" checked /></td>
								</c:when>
								<c:otherwise>
									<input type="radio" name="intId" value="${filtInt.id}" onClick="selectIntFilter();" /></c:otherwise>
							</c:choose></td>
							<td></td>
							<td><c:out value="${filtInt.value}" /></td>
						</tr>
					</c:forEach>
					<c:forEach var="filtInt" items="${intFilters}" begin="1">
						<tr>
							<td><c:choose>
								<c:when test='${filtInt.id==intFilter.id}'>
									<input type="radio" name="intId" value="${filtInt.id}" onClick="selectIntFilter();" checked /></td>
								</c:when>
								<c:otherwise>
									<input type="radio" name="intId" value="${filtInt.id}" onClick="selectIntFilter();" /></c:otherwise>
							</c:choose></td>
							<td><c:out value="${globalFilter.operator}" /></td>
							<td><c:out value="${filtInt.value}" /></td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</p>
		<p><c:choose>
				<c:when test='${globalFilter.operator=="OU"}'>
					<bean:message key="filterPage.and" />
					<input type="radio" name="globOperator" value="ET" onClick="selectGlobOp();"/>&nbsp;
					<bean:message key="filterPage.or" />
					<input type="radio"	name="globOperator" value="OU" checked onClick="selectGlobOp();"/>
				</c:when>
				<c:when test='${globalFilter.operator=="ET"}'>
					<bean:message key="filterPage.and" />
					<input type="radio" name="globOperator" value="ET" checked onClick="selectGlobOp();"/>&nbsp;
					<bean:message key="filterPage.or" />
					<input type="radio"	name="globOperator" value="OU" onClick="selectGlobOp();"/>
				</c:when>
				<c:otherwise>
					<bean:message key="filterPage.and" />
					<input type="radio" name="globOperator" value="ET" onClick="selectGlobOp();" />&nbsp;
					<bean:message key="filterPage.or" />
					<input type="radio"	name="globOperator" value="OU" onClick="selectGlobOp();" />
				</c:otherwise>
		</c:choose> </p>
		<p>	<input name="addFilButton" type="submit" value="<bean:message key="filterPage.add" />" onclick="addFil();return false;" />&nbsp;
			<input name="delFilButton" type="submit" value="<bean:message key="filterPage.delete" />" onclick="deleteFil();return false;" />
		</p>
		<p><bean:message key="filterPage.filterValue" /></p>
		<p><c:out value="${globalFilter.value}" /></p>
		<input type="hidden" id="globalValue" name="globalFilter.value" value="${globalFilter.value}" />
		<p>
			<input name="validateFilterButton" type="button" value="<bean:message key="filterPage.validate" />" onclick="validateFilter();return false;" />&nbsp;
			<input name="cancelFilterButton" type="button" value="<bean:message key="filterPage.cancel" />" onclick="closePopup();" />
		</p>
	</html:form>
</div>